<?php
$document =& JFactory::getDocument();
//Insert Javascription into Page
$document->addScript(JURI::root(false).'administrator/components/com_jbschedule/media/js/functions.js' );
?>
<?php JHTML::_('behavior.formvalidation'); ?>
<script type="text/javascript">
function myValidate(form) {
	var error = '';
	var ok = true;
	for(i=0; i<form.elements.length; i++){
		if (! document.formvalidator.validate(form.elements[i])) {
			if( ok ) ok = false;

			switch(form.elements[i].name){
				case 'name':
						error += '<?=JText::_('NAME IS REQUIRED') ?>\n';
					break;
				case 'description':
						error += '<?=JText::_('DESCRIPTION IS REQUIRED') ?>\n';
					break;
			}
		}
	}
	if(error != '')
		alert(error);

	if(ok)
		form.check.value='<?php echo JUtility::getToken(); ?>';//send token

	return ok;
}

//Override the base function in folder: include/js/joomla.javascript.js
function submitbutton(pressbutton) {
	if(pressbutton.toUpperCase() != 'CANCEL'){
		if(myValidate(document.adminForm))
			submitform(pressbutton);
			selectAllOptions('tableOne');
	}else{
		submitform(pressbutton)
	}
}
</script>
<form action="index.php" method="post" name="adminForm" id="adminForm" class="form-validate" onsubmit="selectAllOptions('tableOne')">
<input type="hidden" name="check" value="post"/>
<div class="col100">
	<fieldset class="adminform">
		<legend><?php echo JText::_( 'DETAILS' ); ?></legend>
		<table class="admintable">
		<tr>
			<td width="200" align="right" class="key">
				<label for="name">
					<?php echo JText::_( 'NAME' ); ?>:
				</label>
			</td>
			<td>
				<input class="text_area required" type="text" name="name" id="name" size="32" maxlength="250" value="<?php echo $this->roles->name;?>" />
			</td>
		</tr>
		<tr>
			<td align="right" class="key">
				<label for="description">
					<?php echo JText::_( 'DESCRIPTION' ); ?>:
				</label>
			</td>
			<td>
				<input class="text_area" type="text" name="description" id="description" size="32" maxlength="250" value="<?php echo $this->roles->description;?>" />
			</td>
		</tr>
		<tr>
			<td align="right" class="key">
					<?php echo JText::_( 'FUNCTIONS' ); ?>:
			</td>
			<td align="left">
				<?php echo $this->html;?>
			</td>
		</tr>
		<tr>
			<td align="right" class="key">
				<label>
					<?php echo JText::_( 'USERS' ); ?>:
				</label>
			</td>
			<td align="left">
				<?php echo $this->htmlRole;?>
			</td>
		</tr>
	</table>
	</fieldset>
</div>
<div class="clr"></div>
<input type="hidden" name="option" value="com_jbschedule" />
<input type="hidden" name="id" value="<?php echo $this->roles->id;?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="roles" />
</form>
